<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jQuery.ajaxPrefilter( [dataTypes] , handler(options, originalOptions, jqXHR) ) | jQuery API 中文手册</title>
<meta name="author" content="jQuery 中文手册 - hemin.cn/jq/">
<meta name="description" content="Handle custom Ajax options or modify existing options before each request is sent and before they are processed by $.ajax(). - jQuery API 中文手册">
<meta name="keywords" content="jquery,chm,手册,在线,api">
<link type="image/x-icon" href="http://hemin.cn/jq/img/favicon.ico" rel="shortcut icon">
<link type="text/css" rel="stylesheet" href="static/css/style.css">
</head>
<body id="split">
<div id='left' class='dtree'>
  <p style="text-align:center">
    <input type="text" name="query" id="query" placeholder="请输入关键字">
    <!--<input type="button" id="butsoso" value="搜索" />--></p>
  <p style="margin:7px 0; text-align:center"><a href="javascript:void(0)" id="openAll">全部展开</a> | <a href="javascript:void(0)" id="closeAll">全部折叠 </a> | <a href="index.html">速查表</a></p>
	<div id="menu">
    
    </div>
</div>
<div id="content" class="a2">
  <div rel="jQuery.ajaxPrefilter">
    <h2><span>返回值:undefined</span>jQuery.ajaxPrefilter( [dataTypes] , handler(options, originalOptions, jqXHR) )</h2>
    <h3>概述</h3>
    <div class="desc">
      <p>Handle custom Ajax options or modify existing options before each request is sent and before they are processed by $.ajax().</p>
      <div class="longdesc">
        <p>参数见 '$.ajax' 说明。</p>
      </div>
    </div>
    <h3>参数</h3>
    <div class="parameter">
      <h4><strong>[dataTypes]</strong><span></span><em>V1.5</em></h4>
      <p>An optional string containing one or more space-separated dataTypes</p>
      <h4><strong> handler(options, originalOptions, jqXHR)</strong><span></span><em>V1.5</em></h4>
      <p>A handler to set default values for future Ajax requests.</p>
    </div>
    <div class="example">
      <h3>示例</h3>
      <span id="f_ad2"></span>
      <h4>描述:</h4>
      <p>A typical prefilter registration using&nbsp;$.ajaxPrefilter()&nbsp;looks like this:</p>
      <pre>$.ajaxPrefilter( function( options, originalOptions, jqXHR ) { 
   // Modify options, control originalOptions, store jqXHR, etc 
 });</pre>
      <h5>where:</h5>
      <ul>
        <li><em class="t">options</em>&nbsp;are the request options</li>
        <li><em class="t">ooriginalOptions</em>&nbsp;are the options as provided to the ajax method, unmodified and, thus, without defaults from&nbsp;<em class="t">ajaxSettings</em></li>
        <li><em class="t">ojqXHR</em>&nbsp;is the jqXHR object of the request</li>
      </ul>
      <br>
      <h4>描述:</h4>
      <p>Prefilters are a perfect fit when custom options need to be handled. Given the following code, for example, a call to&nbsp;$.ajax()&nbsp;would automatically abort a request to the same URL if the custom&nbsp;abortOnRetry&nbsp;option is set to&nbsp;true:</p>
      <pre>var currentRequests = {};    
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
    if ( options.abortOnRetry ) {
      if ( currentRequests[ options.url ] ) {
        currentRequests[ options.url ].abort();
      }
      currentRequests[ options.url ] = jqXHR;
    }
});</pre>
      <h4>描述:</h4>
      <p>Prefilters can also be used to modify existing options. For example, the following proxies cross-domain requests through http://mydomain.net/proxy/:</p>
      <pre>$.ajaxPrefilter( function( options ) {
    if ( options.crossDomain ) {
      options.url = &quot;http://mydomain.net/proxy/&quot; + encodeURIComponent( options.url );
      options.crossDomain = false;
    }
  });</pre>
      <h4>描述:</h4>
      <p>If the optional&nbsp;dataTypes&nbsp;argument is supplied, the prefilter will be only be applied to requests with the indicated dataTypes. For example, the following only applies the given prefilter to JSON and script requests:</p>
      <pre>$.ajaxPrefilter( &quot;json script&quot;, function( options, originalOptions, jqXHR ) {
    // Modify options, control originalOptions, store jqXHR, etc
  });</pre>
      <h4>描述:</h4>
      <p>The&nbsp;$.ajaxPrefilter()&nbsp;method can also redirect a request to another dataType by returning that dataType. For example, the following sets a request as &quot;script&quot; if the URL has some specific properties defined in a custom&nbsp;isActuallyScript()&nbsp;function:</p>
      <pre>$.ajaxPrefilter(function( options ) {
    if ( isActuallyScript( options.url ) ) {
      return &quot;script&quot;;
    }
  });</pre>
      <p>This would ensure not only that the request is considered "script" but also that all the prefilters specifically attached to the script dataType would be applied to it.</p>
    </div>
  </div>

</div>
</body>
<script type="text/javascript" src="static/js/jquery.min.js"></script>
<script type="text/javascript" src="static/js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="static/js/dtree.js"></script>
<script type="text/javascript" src="static/js/js.js"></script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?27646e8f048a16e17f027842e6bdb8f0";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</html>
